| Conditions | 4 |
| Paths | 8193 |
| Total Lines | 112 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | // Copyright © 2017 Tangdongxin |
||
| 25 | function onConfig(result) { |
||
| 26 | if (!result) { |
||
| 27 | console.log("No Config find"); |
||
|
|
|||
| 28 | fontStyle = "Consolas"; |
||
| 29 | fontSize = "14px"; |
||
| 30 | bgColor = "#FDF6E3"; |
||
| 31 | intColor = "#657A81"; |
||
| 32 | strColor = "#2AA198"; |
||
| 33 | keyColor = "#B58900"; |
||
| 34 | defaultColor = "#586E75"; |
||
| 35 | |||
| 36 | strictOnly = false; |
||
| 37 | hideDetails = false; |
||
| 38 | dontBeatify = false; |
||
| 39 | isHighlight = false; |
||
| 40 | |||
| 41 | strLength = 300; |
||
| 42 | return; |
||
| 43 | } |
||
| 44 | if (result && result[0]) { |
||
| 45 | fontStyle = result[0].fontStyle || "Consolas"; |
||
| 46 | fontSize = result[0].fontSize || "14px"; |
||
| 47 | bgColor = result[0].bgColor || "#FDF6E3"; |
||
| 48 | intColor = result[0].intColor || "#657A81"; |
||
| 49 | strColor = result[0].strColor || "#2AA198"; |
||
| 50 | keyColor = result[0].keyColor || "#B58900"; |
||
| 51 | defaultColor = result[0].defaultColor || "#586E75"; |
||
| 52 | |||
| 53 | strictOnly = result[0].strictOnly || false; |
||
| 54 | hideDetails = result[0].hideDetails || false; |
||
| 55 | dontBeatify = result[0].dontBeatify || false; |
||
| 56 | isHighlight = result[0].isHighlight || false; |
||
| 57 | strLength = result[0].strLength || 300; |
||
| 58 | } else { |
||
| 59 | fontStyle = result.fontStyle || "Consolas"; |
||
| 60 | fontSize = result.fontSize || "14px"; |
||
| 61 | bgColor = result.bgColor || "#FDF6E3"; |
||
| 62 | intColor = result.intColor || "#657A81"; |
||
| 63 | strColor = result.strColor || "#2AA198"; |
||
| 64 | keyColor = result.keyColor || "#B58900"; |
||
| 65 | defaultColor = result.defaultColor || "#586E75"; |
||
| 66 | |||
| 67 | strictOnly = result.strictOnly || false; |
||
| 68 | hideDetails = result.hideDetails || false; |
||
| 69 | dontBeatify = result.dontBeatify || false; |
||
| 70 | isHighlight = result.isHighlight || false; |
||
| 71 | strLength = result.strLength || 300; |
||
| 72 | } |
||
| 73 | |||
| 74 | document.addEventListener("click", function(e) { |
||
| 75 | console.log(e); |
||
| 76 | var target = e.target; |
||
| 77 | if (target.tagName.toUpperCase() == "I") { |
||
| 78 | var isClose = target.classList.contains(COLL); |
||
| 79 | console.log(isClose); |
||
| 80 | var classname = target.classList[0]; |
||
| 81 | console.log(classname); |
||
| 82 | if (isClose) { |
||
| 83 | target.removeAttribute("class"); |
||
| 84 | target.setAttribute("class", classname); |
||
| 85 | } else { |
||
| 86 | target.removeAttribute("class"); |
||
| 87 | target.setAttribute("class", classname + " C" + classname.substring(1)); |
||
| 88 | } |
||
| 89 | e.preventDefault(); |
||
| 90 | } else if (target.tagName.toUpperCase() == "STR") { |
||
| 91 | var parentElement = target.parentElement; |
||
| 92 | var originStr = parentElement.innerHTML; |
||
| 93 | parentElement.innerHTML = parentElement.getAttribute("content"); |
||
| 94 | parentElement.setAttribute("content", originStr); |
||
| 95 | } else if (target.tagName.toUpperCase() == "JSON") { |
||
| 96 | if (document.getElementById("light")) { |
||
| 97 | var lightDiv = document.getElementById("light"); |
||
| 98 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 99 | } |
||
| 100 | if (document.getElementById("fade")) { |
||
| 101 | var fadeDiv = document.getElementById("fade"); |
||
| 102 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 103 | } |
||
| 104 | |||
| 105 | var parentElement = target.parentElement; |
||
| 106 | |||
| 107 | var fadeDiv = document.createElement("div"); |
||
| 108 | fadeDiv.setAttribute("id", "fade"); |
||
| 109 | fadeDiv.classList.add("black_overlay"); |
||
| 110 | document.body.appendChild(fadeDiv); |
||
| 111 | |||
| 112 | var lightDiv = document.createElement("div"); |
||
| 113 | lightDiv.setAttribute("id", "light"); |
||
| 114 | lightDiv.classList.add("white_content"); |
||
| 115 | document.body.appendChild(lightDiv); |
||
| 116 | |||
| 117 | document.getElementById('light').style.display = 'block'; |
||
| 118 | document.getElementById('fade').style.display = 'block'; |
||
| 119 | draw(eval(parentElement.getAttribute("json")), lightDiv); |
||
| 120 | } else if (target.classList.contains("black_overlay")) { |
||
| 121 | var fadeDiv = document.getElementById("fade"); |
||
| 122 | fadeDiv.parentElement.removeChild(fadeDiv); |
||
| 123 | var lightDiv = document.getElementById("light"); |
||
| 124 | lightDiv.parentElement.removeChild(lightDiv); |
||
| 125 | } else if (target.className.toUpperCase() == DIV.toUpperCase()) { |
||
| 126 | if (isHighlight) { |
||
| 127 | if (target.style.borderLeft) { |
||
| 128 | target.removeAttribute("style"); |
||
| 129 | } else { |
||
| 130 | target.style = "border-left:1px solid"; |
||
| 131 | } |
||
| 132 | } |
||
| 133 | console.log(target); |
||
| 134 | } |
||
| 135 | }, true); |
||
| 136 | } |
||
| 137 |